package com.wr.service.impl;

import com.wr.annotation.Autowired;
import com.wr.annotation.Service;
import com.wr.annotation.Transactional;
import com.wr.dao.AccountDao;
import com.wr.pojo.Account;
import com.wr.service.AccountService;
import com.wr.utils.ConnectionUtil;

/**
 * @author 王瑞
 * @descreption:
 * @date 2020/2/14  22:56
 */
@Service
@Transactional
public class AccountServiceImpl implements AccountService {
    @Autowired
     private AccountDao accountDao;

    @Autowired
    private ConnectionUtil connectionUtil;

    public void setAccountDao(AccountDao accountDao) {
        this.accountDao = accountDao;
    }

    public void setConnectionUtil(ConnectionUtil connectionUtil) {
        this.connectionUtil = connectionUtil;
    }

    @Override
    public void transfer(String from, String to, Integer money) throws Exception{


        Account fromAccount = accountDao.selectByCardNo(from);
        Account toAccount = accountDao.selectByCardNo(to);

        fromAccount.setMoney(fromAccount.getMoney()-money);
        toAccount.setMoney(toAccount.getMoney()+money);

        accountDao.update(fromAccount);
        int a = 1/0;
        accountDao.update(toAccount);

    }


}
